﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using LINQSamples.Data;

namespace Web.Samples
{
    public partial class AnonSelect1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.BindQuery();
            this.BindImperative();
        }

        private void BindQuery()
        {
            var query = (from sp in StateProvince.GetStateProvinces()
                         select new
                         {
                             Display = sp.Name + " - " + sp.Addresses.Count.ToString(),
                             Value = sp.TerritoryID
                         }).Take(10);

            foreach (var o in query)
                this.litExpressionResults.Text += string.Format("Value: {0} - Display: {1}<br />\n", o.Value, o.Display);
        }

        private void BindImperative()
        {
            var query = StateProvince.GetStateProvinces().Select(sp =>
                new { Display = sp.Name + " - " + sp.Addresses.Count.ToString(), Value = sp.TerritoryID }).Take(10);

            foreach (var o in query)
                this.litImperativeResults.Text += string.Format("Value: {0} - Display: {1}<br />\n", o.Value, o.Display);
        }
    }
}
